using System.Text.RegularExpressions;
using AutoAOIProgram.Property;

namespace AutoAOIProgram.utils;

public class SummaryUtils
{
    public static AoiCountInfo findAoiCount(string aoiPath)
    {
        
        AoiCountInfo aoiCountInfo = new AoiCountInfo();
        
        aoiCountInfo.Count030 = 0;
        aoiCountInfo.Count104 = 0;
        aoiCountInfo.Count000 = 0;

        try
        {
            using (StreamReader reader = new StreamReader(aoiPath))
            {
                string? line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("DEVICE"))
                    {
                        aoiCountInfo.Job = line.Replace("DEVICE:", "");
                    }
                    if (!line.StartsWith("RowData:")) continue;
                    aoiCountInfo.Count030 += Regex.Matches(line, "030").Count;
                    aoiCountInfo.Count104 += Regex.Matches(line, "104").Count;
                    aoiCountInfo.Count000 += Regex.Matches(line, "000").Count;
                }
            }

        }
        catch (Exception ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
        }

        return aoiCountInfo;
    }
    
    
    
    
}